package com.xms.ribbonbutton.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xms.datacore.service.FinderService;
import com.xms.ribbonbutton.core.RibbonButtonArea;
import com.xms.ribbonbutton.entity.RibbonButton;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.UUID;

/**
 * <p>
 * RibbonButtonFinderService
 * </p>
 *
 * @author migo
 * @since 2021/9/8
 */
@CacheConfig(cacheNames = "ribbonbutton", keyGenerator = "CacheKeyGenerator")
@Service
public class RibbonButtonFinderService extends FinderService<RibbonButton> implements IRibbonButtonFinderService {

    @Cacheable(condition = "#id != null")
    @Override
    public RibbonButton getById(UUID id) {
        return super.getById(id);
    }

    @Cacheable(condition = "#idList != null && #idList.size() > 0")
    @Override
    public List<RibbonButton> getByIds(Collection<UUID> idList) {
        return super.listByIds(idList);
    }

    //@Cacheable()
    @Override
    public RibbonButton getOne(Wrapper<RibbonButton> queryWrapper) {
        return super.getOne(queryWrapper);
    }

    @Cacheable()
    @Override
    public int count() {
        return super.count();
    }

    //@Cacheable()
    @Override
    public int count(Wrapper<RibbonButton> queryWrapper) {
        return super.count(queryWrapper);
    }

    //@Cacheable()
    @Override
    public List<RibbonButton> list(Wrapper<RibbonButton> queryWrapper) {
        return super.list(queryWrapper);
    }

    @Cacheable()
    @Override
    public List<RibbonButton> all() {
        return super.list();
    }

    @Cacheable(condition = "#entityId != null")
    @Override
    public List<RibbonButton> getByEntityId(UUID entityId) {
        LambdaQueryWrapper<RibbonButton> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(RibbonButton::getEntityid, entityId)
                .orderByAsc(RibbonButton::getDisplayorder);
        return super.list(queryWrapper);
    }

    @Cacheable(condition = "#entityId != null")
    @Override
    public List<RibbonButton> getByArea(UUID entityId, int area) {
        LambdaQueryWrapper<RibbonButton> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(RibbonButton::getEntityid, entityId)
                .eq(RibbonButton::getShowarea, area)
                .orderByAsc(RibbonButton::getDisplayorder);
        return super.list(queryWrapper);
    }

    @Cacheable(condition = "#entityId != null")
    @Override
    public List<RibbonButton> getByListArea(UUID entityId) {
        LambdaQueryWrapper<RibbonButton> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(RibbonButton::getEntityid, entityId)
                .in(RibbonButton::getShowarea, RibbonButtonArea.ListHead, RibbonButtonArea.ListRow, RibbonButtonArea.SubGrid)
                .orderByAsc(RibbonButton::getDisplayorder);
        return super.list(queryWrapper);
    }

    @Cacheable(condition = "#entityId != null")
    @Override
    public List<RibbonButton> getByListAreaEnabled(UUID entityId) {
        LambdaQueryWrapper<RibbonButton> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(RibbonButton::getEntityid, entityId)
                .eq(RibbonButton::getStatecode, true)
                .in(RibbonButton::getShowarea, RibbonButtonArea.ListHead, RibbonButtonArea.ListRow, RibbonButtonArea.SubGrid)
                .orderByAsc(RibbonButton::getDisplayorder);
        return super.list(queryWrapper);
    }

    @Cacheable()
    @Override
    public List<RibbonButton> getAuthorizations() {
        LambdaQueryWrapper<RibbonButton> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(RibbonButton::getAuthorizationenabled, true);
        return super.list(queryWrapper);
    }
}
